package com.yanq.liancar.adapter;
/*
 *  @创建者     Administrator
 *  @创建时间   2018/11/26  16:27
 *  @描述       ${TODO}
 */


import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanq.liancar.R;
import com.yanq.liancar.bean.QueryObdKeepHisListBean;

import java.util.List;

public class MaintainAdapter2 extends BaseQuickAdapter<QueryObdKeepHisListBean.DataBean._$2Bean,BaseViewHolder> {
    public MaintainAdapter2(int layoutResId, @Nullable List<QueryObdKeepHisListBean.DataBean._$2Bean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, QueryObdKeepHisListBean.DataBean._$2Bean item) {

        helper.setText(R.id.tv_title,item.getName());

        final RelativeLayout relativeLayout=helper.getView(R.id.rl_progesss);
        final TextView textView=helper.getView(R.id.progesss_value);
        TextView textView1=helper.getView(R.id.tv_title);
        final ProgressBar progressBar=helper.getView(R.id.progesss);
        progressBar.setProgress((int) item.getHealthScale());
        textView1.post(new Runnable() {
            @Override
            public void run() {
                setPos(relativeLayout,textView,progressBar);
            }
        });


        if (item.getHealthScale()<60&&item.getHealthScale()>10){
            progressBar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.myprogressbar1));
        }else if (item.getHealthScale()<10){
            progressBar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.myprogressbar));
        }else {
            progressBar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.myprogressbar2));
        }

    }

    /**
     * 设置进度显示在对应的位置
     */

    public void setPos(RelativeLayout rl, TextView textView, ProgressBar progesss) {
        //获取屏幕宽度
        //int w = getWindowManager().getDefaultDisplay().getWidth()-tv_jiyou.getWidth();
        int w = rl.getWidth();
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) textView.getLayoutParams();
        int tW = textView.getWidth();
        int pro = progesss.getProgress();
        if (pro > 10) {
            params.leftMargin = w * pro / 100 - tW - 30;
            textView.setText(new StringBuffer().append(progesss.getProgress()).append("%"));
        } else {
            params.leftMargin = w * pro / 100 + 20;
            textView.setText("已到保养时间");
            textView.setTextColor(mContext.getResources().getColor(R.color.red));
        }
        textView.setLayoutParams(params);
    }
}
